package com.liucxu.jiandanl.View.Adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.liucxu.jiandanl.Config.ImageLoaderUtils;
import com.liucxu.jiandanl.Entity.GirlEntity;
import com.liucxu.jiandanl.R;
import com.liucxu.jiandanl.Utils.ViewHolder;
import com.liucxu.jiandanl.View.Fragment.GirlsFragment;
import com.liucxu.jiandanl.Widget.ShowMaxWidthImageView;

import java.util.ArrayList;
import java.util.List;

/**
 * 福利图的Adapter
 * Created by liuchenxu on 2016/8/4.
 */
public class GirlsAdapter extends BaseAdapter {

    private List<GirlEntity> items;

    private GirlsFragment mContext;

    public GirlsAdapter(GirlsFragment context) {
        items = new ArrayList<GirlEntity>();
        mContext = context;
    }

    public void setDatas(List<GirlEntity> datas) {
        if (datas != null) {
            items.clear();
            items.addAll(datas);
            notifyDataSetChanged();
        }
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int i) {
        return items.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = View.inflate(mContext.getActivity(), R.layout.adapter_girls_pics, null);
        }
        initView(view,i);
        return view;
    }

    /**
     *
     * @param view
     * @param position
     */
    private void initView(View view,int position) {
        GirlEntity post=items.get(position);
        ShowMaxWidthImageView img=ViewHolder.get(view,R.id.adapter_img);

        ImageLoaderUtils.displayImageWithLoadingPicture(post.getUrl(),img);
    }
}
